<template>
  <div id="topSearch">
    <h1 class="con-right-title">
      评论库管理
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="等级" prop="category">
          <el-select v-model="formInline.category" clearable placeholder="">
            <el-option
              v-for="item in levelList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属学院" prop="college">
          <el-select v-model="formInline.college" clearable placeholder="">
            <el-option
              v-for="item in belongCollegeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="内容类型" prop="type">
          <el-select v-model="formInline.type" clearable placeholder="">
            <el-option
              v-for="item in typelList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- 输入搜索部分 -->
        <el-form-item label="内容" prop="content">
          <el-input
            clearable
            v-model="formInline.content"
            placeholder="请输入评论内容搜索"
            size="small"
            class="numberInput"
          ></el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'TopSearch',
  msg: '评论库管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          category: '', // 等级,默认所有
          type: '', // 类型,默认所有
          college: '', // 所属学院,默认所有
          content: '' // 搜索框内容
        }
      }
    }
  },
  data() {
    return {
      // 等级列表
      levelList: [{ dictLabel: '所有', dictValue: '' }],
      // 所属学院列表
      belongCollegeList: [{ dictLabel: '所有', dictValue: '' }],
      // 类型列表
      typelList: [{ dictLabel: '全部', dictValue: '' }],
      rules: {
        category: {},
        type: {},
        college: {},
        content: {}
      }
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    // 获取筛选条件
    async getStatusList() {
      // 获取评论库筛选条件-等级
      let data = await sysNormalDisable('sys_grade', 'levelType')
      this.levelList = this.levelList.concat(data)
      // this.levelList.splice(0, 1)
      // 获取评论库筛选条件-类型
      let data1 = await sysNormalDisable('sys_share_language_type', 'shareType')
      this.typelList = this.typelList.concat(data1)
      // 获取评论库筛选条件-学院
      let data2 = await sysNormalDisable(
        'sys_share_college',
        'shareCollegeType'
      )
      this.belongCollegeList = this.belongCollegeList.concat(data2)
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>
<style lang="less" scoped>
#topSearch {
  .numberInput {
    width: 200px;
  }
}
</style>
